/*
 * 动态加载封装模块
 */
import * as React from 'react';
import * as Loadable from 'react-loadable';
import { message } from 'antd';

const Loading = (props: any) => {
  if (props.error) {
    message.error('组件加载失败，请保存数据后刷新页面重试吧～～');
  } else if (props.timedOut) {
    message.error('Oh，服务超时了!');
  } else if (props.pastDelay) {
    return <p className="loading-placeholder">组件加载中...</p>;
  }
  return null;
};

const LoadableComponent = (importComponent: Function): any =>
  Loadable({
    loader: () => importComponent(),
    loading: Loading,
    timeout: 10000,
    delay: 300,
  });

export default LoadableComponent;
